<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      tr,
      td,
      th {
        border: 1px solid #000;
      }
    </style>
  </head>
  <body>
    <div id="app">
      <label v-for="key in keys" :key="key">
        <input type="checkbox" :value="key" v-model="columns" />
        <span>{{ key }}</span>
      </label>

      <hr />
      <table>
        <thead>
          <tr>
            <th v-for="(col, index) in columns" :key="index">{{ col }}</th>
          </tr>
        </thead>

        <tbody>
          <tr v-for="item in list" :key="item.id">
            <td v-for="(col, index) in columns" :key="index">
              {{ item[col] }}
            </td>
          </tr>
        </tbody>
      </table>
    </div>

    <script src="../../lib/vue3.js"></script>
    <script src="../../lib/axios.min.js"></script>
    <script>
      Vue.createApp({
        data() {
          return {
            // 用于设置列
            columns: ["name"],

            list: [
              {
                id: 3,
                imgSrc:
                  "https://hello-1253323335.cos.ap-guangzhou.myqcloud.com/pic_3.jpeg",
                name: "秀儿的秋裤1",
                price: 30,
                count: 6,
              },
              {
                imgSrc:
                  "https://hello-1253323335.cos.ap-guangzhou.myqcloud.com/pic_3.jpeg",
                name: "秀儿的秋裤2",
                price: "40",
                count: 2,
                id: 4,
              },
              {
                imgSrc:
                  "https://hello-1253323335.cos.ap-guangzhou.myqcloud.com/pic_3.jpeg",
                name: "秀儿的秋裤3",
                price: "50",
                count: 1,
                id: 5,
              },
              {
                imgSrc:
                  "https://hello-1253323335.cos.ap-guangzhou.myqcloud.com/pic_3.jpeg",
                name: "秀儿的秋裤4",
                price: "60",
                count: 2,
                id: 6,
              },
              {
                imgSrc:
                  "https://hello-1253323335.cos.ap-guangzhou.myqcloud.com/pic_3.jpeg",
                name: "秀儿的秋裤5",
                price: "10",
                count: 2,
                id: 7,
              },
            ],
          };
        },

        computed: {
          keys() {
            return Object.keys(this.list[0]);
          },
        },
      }).mount("#app");
    </script>
  </body>
</html>
